package com.rrd.dw.mr.gzip.kafka;

import com.ucredit.babel.common.model.BaseModel;
import com.ucredit.babel.common.model.RecordType;
import com.ucredit.babel.common.model.third.ypcredit.YpCreditPayScore;
import com.ucredit.babel.common.model.third.ypcredit.YpCreditPayScoreData;
import com.ucredit.babel.common.model.third.ypcredit.YpCreditPayScoreRecord;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

/**
 * 天创-支付G
 */
public class TianchuangPayScoreParse extends ParseBase {
    Text key = new Text();
    Text val = new Text();


    @Override
    public boolean parseJob(Mapper.Context context, BaseModel<?> model, String successful) throws IOException, InterruptedException {
        YpCreditPayScoreRecord obj = (YpCreditPayScoreRecord) model;
        YpCreditPayScoreData data = obj.getData();

        StringBuilder sb = getBaseInfo(obj, successful);
        StringBuilder shSb = new StringBuilder(500);

        sb.append(data.getStatus()).append(CRT001);
        sb.append(data.getMessage() == null ? "" : data.getMessage()).append(CRT001);
        sb.append(data.getSeqNum() == null ? "" : data.getSeqNum()).append(CRT001);
        sb.append(data.getGid() == null ? "" : data.getGid()).append(CRT001);

        YpCreditPayScore ypCreditPayScore = data.getData();
        sb.append(ypCreditPayScore.getG001() == null ? "" : ypCreditPayScore.getG001()).append(CRT001);
        sb.append(ypCreditPayScore.getG002() == null ? "" : ypCreditPayScore.getG002()).append(CRT001);
        sb.append(ypCreditPayScore.getG003() == null ? "" : ypCreditPayScore.getG003()).append(CRT001);
        sb.append(ypCreditPayScore.getFeeStatus() == null ? "" : ypCreditPayScore.getFeeStatus()).append(CRT001);
        StringBuilder txSb = getBaseInfo(obj);
        key.set(getKey());
        val.set((sb.toString() + txSb).replace("\n", " ").replace("\r", " "));
        context.write(key, val);
        return true;
    }

    @Override
    public String getTableName() {
        return "kafka_babel_ypcredit_payscore_inc";
    }

    @Override
    public String getType() {
        return RecordType.YP_CREDIT_PAY_SCORE_RECORD.toString();
    }

    @Override
    public String getComment() {
        return "天创-支付G";
    }
}
